import pymongo
import requests
from tools.funciton import get_alpha_token, get_jiwu_token
from config.configs import ALPHA_DB_HOST, ALPHA_DB_PORT
from tools.funciton import spuId_to_articleNumber, skuId_to_size, write_xlsx

alpha = pymongo.MongoClient(ALPHA_DB_HOST, ALPHA_DB_PORT).alpha
jiwu = pymongo.MongoClient(ALPHA_DB_HOST, ALPHA_DB_PORT).jiwu


def batch_flash_flaw_on_shelf(db, cond, shelfCode):
    """闪电质检退回批量上架"""
    token = get_alpha_token()
    if db == 'jiwu':
        url = 'https://erp.geehoop.com/api/backend/return/fail/finish'
        header = {
            "authorization": f"Bearer {token}"}
        unis = [i['uniqueCode'] for i in jiwu.flash_flaw_return.find(cond)]
        param = {"shelfCode": shelfCode, "uniqueCodes": unis}
        res = requests.post(url=url, headers=header, json=param)
        print(res.json())


# batch_flash_flaw_on_shelf('jiwu', {'status': 1}, 'CDC')
